package com.amsp.oa.oademo.service.impl;

import com.amsp.oa.oademo.entity.EmployeeContract;
import com.amsp.oa.oademo.mapper.EmployeeContractMapper;
import com.amsp.oa.oademo.service.EmployeeContractService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class EmployeeContractServiceImpl extends ServiceImpl<EmployeeContractMapper, EmployeeContract>
        implements EmployeeContractService {

    @Override
    public IPage<EmployeeContract> getEmployeeContractPage(Page<EmployeeContract> page, EmployeeContract query) {
        LambdaQueryWrapper<EmployeeContract> wrapper = new LambdaQueryWrapper<>();

        // 添加查询条件
        if (query != null) {
            if (StringUtils.isNotBlank(query.getEmployeeName())) {
                wrapper.like(EmployeeContract::getEmployeeName, query.getEmployeeName());
            }
            if (StringUtils.isNotBlank(query.getEmployeeIdNumber())) {
                wrapper.like(EmployeeContract::getEmployeeIdNumber, query.getEmployeeIdNumber());
            }
            if (StringUtils.isNotBlank(query.getEmployerName())) {
                wrapper.like(EmployeeContract::getEmployerName, query.getEmployerName());
            }
        }

        // 按创建时间倒序排序
        wrapper.orderByDesc(EmployeeContract::getCreateTime);

        return this.page(page, wrapper);
    }
}